<script setup>
import { Plus } from "@element-plus/icons-vue";
import useTable from "@/utils/useTable";
import {http} from "@/api";
/**
 * 表格
 * @type {Ref<UnwrapRef<*[]>>}
 */
const {
  searchParams,
  pageNo,
  pageSize,
  total,
  changePage,
  changeSize,
  dataSource,
  search,
  reset,
  exportPage,
  exportAll
} = useTable({
  exportExcelName: '光伏日前预测',
  getExportData: (tableData) => {
    if (tableData.length === 0) {
      return
    }
    let data = [
      ['时间', '日前预测功率', '实际功率']
    ]
    tableData.forEach(item => {
      data.push([item.name, item.forecast_power, item.actual_power])
    })
    return data
  },
  requestFn: http.pvForecastRelRecord,
  params: {
    type: 'day',
    start_time: '',
    end_time: ''
  }
})
</script>


<template>
  <PageMain title="报表-光伏日前预测">
    <el-form label-suffix="：" inline>
      <el-form-item label="开始时间">
        <el-date-picker
            type="datetime"
            v-model="searchParams.start_time" value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"></el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker
            type="datetime"
            v-model="searchParams.end_time" value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="add-box">
      <el-button type="primary" :icon="Plus" @click="exportPage">导出当页</el-button>
      <el-button type="primary" :icon="Plus" @click="exportAll">导出全部</el-button>
    </div>
    <div class="table-box">
      <el-table :data="dataSource">
        <el-table-column label="时间" prop="name">
        </el-table-column>
        <el-table-column label="日前预测功率" prop="forecast_power">
        </el-table-column>
        <el-table-column label="实际功率" prop="actual_power">
        </el-table-column>
      </el-table>
      <el-pagination
          v-model:current-page="pageNo"
          v-model:page-size="pageSize"
          :page-sizes="[10, 50, 100, 200]"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="changeSize"
          @current-change="changePage"
      />
    </div>
  </PageMain>
</template>

<style scoped lang="scss">

</style>
